package com.wyj.servlet;

import com.wyj.db.DBConnection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * Created by WYJ on 2017/5/29.
 */
@WebServlet(name = "com.wyj.servlet.DeleteServlet")
public class DeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Connection conn = DBConnection.getConnection();

        String table=request.getParameter("table");
        String PK=request.getParameter("PK");
        String PKValue=request.getParameter("PKValue");
        String sql=String.format("DELETE FROM %s WHERE %s='%s'",table,PK,PKValue);
        try {
            Statement statement = conn.createStatement();
            statement.executeUpdate(sql);
            statement.close();
            conn.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
